package top.yvyan.guettable.adapter;

import com.zhuangfei.timetable.listener.OnDateBuildAapter;
import com.zhuangfei.timetable.model.ScheduleSupport;

import java.util.Calendar;
import java.util.Locale;

import top.yvyan.guettable.data.GeneralData;

public class DateBuildAdapter extends OnDateBuildAapter {
    private GeneralData generalData;

    public DateBuildAdapter(GeneralData generalData) {
        super();
        this.generalData = generalData;
    }

    @Override
    public void onHighLight() {
    }

    public void highLight(int curWeek, int targetWeek) {
        initDateBackground();

        //获取周几，1->7
        Calendar now = Calendar.getInstance();
        int weekDay = now.get(Calendar.DAY_OF_WEEK) - 1;
        if (weekDay == 0) {
            weekDay = 7;
        }
        if (curWeek == targetWeek) activeDateBackground(weekDay);
    }

    @Override
    public void onUpdateDate(int curWeek, int targetWeek) {
        if (textViews == null || textViews.length < 8) return;
        if (curWeek == 1) {
            // 当当前学期没开始时 curWeek 强制设为 1
            // 此处 workaround 进行重新计算允许获得负周次来强制显示正确的日期
            curWeek = generalData.getWeek(true);
        } else if (curWeek == 25) {
            curWeek = generalData.getWeek(true);
        }
        highLight(curWeek,targetWeek);
        weekDates = ScheduleSupport.getDateStringFromWeek(curWeek, targetWeek);
        int month = Integer.parseInt(weekDates.get(0));
        textViews[0].setText(month + "\n月");
        for (int i = 1; i < 8; i++) {
            if (textViews[i] != null) {
                textViews[i].setText(weekDates.get(i) + "日");
            }
        }
    }
}